<?php
/*
 * 新锐微信登录 [ 深圳市新锐创意科技有限公司旗下产品 ]
 * Copyright  2015-2099 www.xinruiweb.com  All Rights Reserved.
 * 技术开发: 75674952@qq.com
 * 请支持正版授权产品
 */
//error_reporting(E_ALL);
if( ! defined('IN_DISCUZ')) {
	exit('Access Denied');
}


$auth = array('bind', 'unbind','username','password','qqlogin','callback','bindweb','bindwebpost','bindwebnewpost');

$op = $_REQUEST['op'];
if(!in_array($op, $auth)) {
	showmessage('xinrui_qq:qq_op_failed', dreferer());
}

//登录的情况下处理
if ($_G['uid'] && submitcheck('confirmsubmit')) {
    if($op == 'password'){
            if(strlen($_GET['newpassword']) < 6) {
                showmessage(lang('message', 'profile_password_tooshort', array('pwlength' => 6)));
            }
            if($_GET['newpassword'] !== $_GET['confirmpassword']) {
                showmessage('profile_passwd_notmatch');
            }
            if(!$_GET['newpassword'] || $_GET['newpassword'] != addslashes($_GET['newpassword'])) {
                showmessage('profile_passwd_illegal');
            }
            if($result = xinruiqq::uptpwd($_GET['newpassword'])){
                showmessage('xinrui_qq:setting_upt_pwd_ok','',array(),array('showdialog'=>1));
            }else{
                showmessage('xinrui_qq:setting_upt_pwd_failed');
            }
    }else if($op == 'username'){
        if($_GET['newusername'] != $_G['member']['username']) {
            $username = xinruiqq::checkusername($_GET['newusername']);
            if($username){
                if(xinruiqq::uptusername($username)){
                    showmessage('xinrui_qq:setting_upt_username_success','',array(),array('showdialog'=>1));
                }else{
                    showmessage('xinrui_qq:setting_upt_username_failed2');
                }
            }else{
                showmessage('xinrui_qq:setting_upt_username_failed1');
            }
        }else{
            showmessage('xinrui_qq:setting_upt_username_failed');
        }
    }else if($op == 'bind'){
        if(xinruiqq::bindoldusername()){
            showmessage('xinrui_qq:setting_bind_username_success','',array(),array('showdialog'=>1));
        }else{
            showmessage('xinrui_qq:setting_bind_failed3');
        }
    }else if($op == 'unbind'){
        xinruiqq::unbind();
    }else if($op == 'bindwebnewpost'){
        if($_GET['newusername'] == $_G['member']['username']){
            showmessage('xinrui_qq:setting_upt_username_failed1');
        }
        if(strlen($_GET['newpassword']) < 6) {
            showmessage(lang('message', 'profile_password_tooshort', array('pwlength' => 6)));
        }
        if($_GET['newpassword'] !== $_GET['confirmpassword']) {
            showmessage('profile_passwd_notmatch');
        }
        if(!$_GET['newpassword'] || $_GET['newpassword'] != addslashes($_GET['confirmpassword'])) {
            showmessage('profile_passwd_illegal');
        }

        $username = xinruiqq::checkusername($_GET['newusername']);

        if($username){
            if(xinruiqq::uptusername($username)){
                if($uid = xinruiqq::uptpwd($_GET['newpassword'])){
                    session_start();
                    $_SESSION['xinrui_login_uid'] = $uid ; 
                    showmessage('xinrui_qq:success_done',$_REQUEST['referer'],array(),array('showdialog'=>1));
                }else{
                    showmessage('xinrui_qq:pwd_fail',$_REQUEST['referer'],array(),array('showdialog'=>1));
                }
                showmessage('xinrui_qq:setting_upt_username_success','',array(),array('showdialog'=>1));
            }else{
                showmessage('xinrui_qq:setting_upt_username_failed2');
            }
        }else{
            showmessage('xinrui_qq:setting_upt_username_failed1');
        }
    }else if($op == 'bindwebpost'){
        if(xinruiqq::qqbindoldusername()){
            showmessage('xinrui_qq:setting_bind_username_success',$_REQUEST['referer'],array(),array('showdialog'=>1));
        }else{
            showmessage('xinrui_qq:setting_bind_failed3');
        }
    }

}else{//未登录情况下处理
    if($op == 'qqlogin'){
        xinruiqq::login();
    }else if($op == 'callback'){
        $info = xinruiqq::callback();
        if($info){
            xinruiqq::getuserinfo($info);
        }
    }
}


include_once template('xinrui_qq:setting');
